<?php


namespace app\api\controller;


use think\Db;

class Event extends Lib
{

    // 自定义
    public function zbx_event_get()
    {
        $triggers = Db::name('triggers')->column('triggerid,deptid');

        $params = [
            "output"     => ["objectid", "clock"],
            "objectids"   => array_keys($triggers),
            "filter"     => ["value" => "1"]
        ];
        $result = json_decode(self::RPC('event.get', $params), true);
        $data = $result['data'];

        if ($data){
            foreach ($data as $k=>&$v){
                $is_event = Db::name('events')->where('eventid',$v['eventid'])->find();
                if ($is_event){
                    unset($k);
                }else{
                    $v['deptid'] = $triggers[$v['objectid']];
                }
            }
            if ($data){
                $add = Db::name('events')->insertAll($data);
                if ($add){
                    return true;
                }else{
                    return false;
                }
            }else{
                return true;
            }
        }else{
            return true;
        }
    }
}